function rc_callback(result) {
    alert('yah callback:' + result.success);
};
function createActivity() {
    var params = { title: 'the title 3.0', body: 'body alright 3.0', anchorText: 'hope this works', navParams: {'name1' : 'value1', 'name2' : 'value2'}};
    opensocial.requestCreateActivity(opensocial.newActivity(params), opensocial.CreateActivityPriority.HIGH, rc_callback);
    return false;
};

function shareApp() {
    var recipient = null;
    var reason = opensocial.newMessage('Install this gadget to help share the love.');     
    opensocial.requestShareApp(recipient, reason, function(response){
       alert('requestShareApp called');
     });
     return false;
};

function findFriendsWithoutApp() {
    var req = opensocial.newDataRequest();
    var viewerFriends = opensocial.newIdSpec({ "userId" : "VIEWER", "groupId" : "FRIENDS" });
    req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.VIEWER), 'viewer');
    var allFriendsFilter = {};
    allFriendsFilter[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.ALL;
    req.add(req.newFetchPeopleRequest(viewerFriends, allFriendsFilter), 'allFriends');
    var appFriendsFilter = {};
    appFriendsFilter[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.HAS_APP;
    req.add(req.newFetchPeopleRequest(viewerFriends, appFriendsFilter), 'appFriends');
    req.send(findFriendsWithoutAppCallback);
    return false;
};

function findFriendsWithoutAppCallback(data) {
    var allFriends = data.get('allFriends').getData();
    var appFriends = data.get('appFriends').getData();
    displayFriendsIn(allFriends, 'allfriends');
    displayFriendsIn(appFriends, 'appfriends');
    gadgets.window.adjustHeight();
};

function displayFriendsIn(users, divId) {
    var allFriendsHtml = new Array();
    allFriendsHtml.push('<p>' + divId + '</p>');
    allFriendsHtml.push('<ul>');
    users.each(function(person) {
        if (person.getId()) {
            allFriendsHtml.push('<li>' + person.getDisplayName() + "</li>");
        }
    });
    allFriendsHtml.push('</ul>');
    document.getElementById(divId).innerHTML = allFriendsHtml.join('');
};